 #!/bin/bash
echo "Which subdirectory would you like to convert the pictures in? EX: 'Cabaret', 'Student_Life', 'Photograph'";
read dir;
dir="/var/www/DiMF/media/pictures/"${dir};
echo "Are you sure you want to convert the pictures in ${dir}?(y/n)";
read answer;
if [[ $answer =~ "y" ]]
then
	echo "Converting started.";
		for file in ${dir}/*
		do
			var=$(file $file) ;
			##check file type, if it's not a picture, skip it.
			if [[ ! $var =~ "image" ]]
			then
				##echo $var;
				continue;
			fi
			mogrify -resize 1280x1024 ${file}
			mv  ${file} ${dir}/$(printf "IMG_%04d.jpg" $i) ;
			echo "--${var} : "$(printf "IMG_%04d.jpg" $i);
			i=$((i+1)) ;
		done

	echo "Converting done.";
else 
	echo "Aborting...";
fi

##i=0 ; for f in * ; do echo $(file $f) ; i=$((i+1)) ; done
